package com.rest.demo.functional.time;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;

/**
 * @author Administrator
 * @decription
 * @Date 2018-01-29 14:10
 */
public class LocalDateDemo {

    public static void main(String[] args) {
        LocalDate localDate = LocalDate.now();
        LocalDate localDate1 = LocalDate.now(ZoneId.of("Asia/Shanghai"));
        System.out.println(localDate);
        System.out.println(localDate1);

        LocalDate localDate2 = LocalDate.parse("2018-01-23");
        System.out.println(localDate2);

        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        String dateTime = df.format(localDate2);
        System.out.println(dateTime);

        LocalDate tomorrow = LocalDate.of(2018,01,31).plusDays(1);
        System.out.println(tomorrow);

        LocalDate prevMonth = LocalDate.now().minus(1, ChronoUnit.MONTHS);
        System.out.println(prevMonth);

        boolean isLeapYear = LocalDate.of(2000,01,10).isLeapYear();
        System.out.println(isLeapYear);

        boolean isBefore = LocalDate.of(2018,01,18).isBefore(LocalDate.now());
        System.out.println(isBefore);

        LocalDate firstDayOfMonth = LocalDate.now().with(TemporalAdjusters.firstDayOfMonth());
        System.out.println("这个月的第一天: " + firstDayOfMonth);
        DayOfWeek dayOfWeek = LocalDate.now().plusDays(3).getDayOfWeek();
        System.out.println("过三天后是星期: " + dayOfWeek);
    }
}
